// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import router from './router/index'
import App from './App'
import tools from './utils/tools'
import wxConfig from './utils/wxConfig'
import store from './store'
import axios from 'axios'
import 'jquery'

Vue.prototype.$axios = axios

Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error)
}
Vue.prototype.$tools = tools;
Vue.prototype.$wx = wxConfig;

import {fetchGet, fetchPost} from './utils/axiosConfig'

Vue.prototype.$get = fetchGet
Vue.prototype.$post = fetchPost

Vue.config.productionTip = false
FastClick.attach(document.body)

/*引入公共组件*/
import {ConfirmPlugin, ToastPlugin, LoadingPlugin} from 'vux'

Vue.use(ConfirmPlugin)
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)

/*引入自定义组件*/
import headerT from "@/components/header";

Vue.component('headerT', headerT)

router.beforeEach((to, from, next) => {
    if (from.path === '/') {
        let items = ['token', 'chooseTab', 'chooseTabName', 'nineListIndex'];
        let changeItems = [
            {name: 'changeToken', type: 'string'},
            {name: 'changeChooseTab', type: 'number'},
            {name: 'changeChooseTabName', type: 'string'},
            {name: 'changeNineListIndex', type: 'number'}
        ];
        items.forEach((item, index) => {
            store.dispatch(changeItems[index].name, changeItems[index].type === 'number' ? Number(window.sessionStorage.getItem(item)) : window.sessionStorage.getItem(item))
        })
    }

    if (from.name === 'null' || from.name === null) {
        if (window.sessionStorage.getItem('historyPathList')) {
            store.dispatch('changeHistoryPathList', JSON.parse(window.sessionStorage.getItem('historyPathList')))
        }

    }

    next()
})

/* eslint-disable no-new */
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app-box')
